package com.DuoXianCheng.T06;

import java.util.ArrayList;
import java.util.Collections;

public class C01 extends Thread{
    static ArrayList<Integer> list;
    
    public C01(ArrayList<Integer> list) {
        this.list = list;
    }
    
    // static  ArrayList<Integer> list1 = new ArrayList<>();
    // static  ArrayList<Integer> list2 = new ArrayList<>();
    
    @Override
    public void run() {
        ArrayList<Integer> boxList = new ArrayList<>();
        while (true) {
            synchronized (C01.class){
                if(list.isEmpty()){
                    // if("抽奖箱1".equals(getName())){
                    //     System.out.println("抽奖箱1" + list1);
                    // } else {
                    //     System.out.println("抽奖箱2" + list2);
                    // }
                    System.out.println(getName() + boxList);
                    break;
                } else {
                    Collections.shuffle(list);
                    Integer remove = list.remove(0);
                    // System.out.println(getName() + "又产生了一个" + remove + "元大奖!");
                    // if("抽奖箱1".equals(getName())){
                    //     // list1.add(remove);
                    // } else {
                    //     list2.add(remove);
                    // }
                    boxList.add(remove);
                }
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
